export const handleTime = (msgTime: string) => {
  const now = new Date()
  const currentYear = now.getFullYear() // 获取今年年份
  const msgDate = new Date(msgTime)
  const year = msgDate.getFullYear()
  const month = (msgDate.getMonth() + 1).toString().padStart(2, '0')
  const day = msgDate.getDate().toString().padStart(2, '0')
  const hours = msgDate.getHours().toString().padStart(2, '0')
  const minutes = msgDate.getMinutes().toString().padStart(2, '0')
  if (currentYear !== year) {
    return `${year}-${month}-${day} ${hours}:${minutes}`
  } else {
    return `${month}-${day} ${hours}:${minutes}`
  }
}

export const handleChatListTime = (msgTime: string) => {
  if (msgTime === '') return
  const now = new Date()
  const currentYear = now.getFullYear() // 获取今年年份
  const msgDate = new Date(msgTime)
  const year = msgDate.getFullYear()
  const month = (msgDate.getMonth() + 1).toString()
  const day = msgDate.getDate().toString()
  if (currentYear !== year) {
    return `${year}年${month}月${day}日`
  } else {
    return `${month}月${day}日`
  }
}

//时间戳
export const formatDate = (timestamp: number) => {
  const now = new Date()
  const currentYear = now.getFullYear() // 获取今年年份
  const date = new Date(timestamp)
  const year = date.getFullYear()
  const month = (date.getMonth() + 1).toString().padStart(2, '0') // Add leading zero if necessary
  const day = date.getDate().toString().padStart(2, '0') // Add leading zero if necessary
  const hours = date.getHours().toString().padStart(2, '0')
  const minutes = date.getMinutes().toString().padStart(2, '0')
  if (currentYear !== year) {
    return `${year}-${month}-${day} ${hours}:${minutes}`
  } else {
    return `${month}-${day} ${hours}:${minutes}`
  }
}
